 package server.console.groups.setting;


import com.alee.extended.list.CheckBoxCellData;
import com.alee.extended.list.CheckBoxListModel;
import com.alee.extended.list.WebCheckBoxList;
import com.alee.extended.panel.GroupPanel;
import com.alee.extended.panel.GroupingType;
import com.alee.laf.button.WebButton;
import com.alee.laf.menu.WebPopupMenu;
import com.alee.laf.optionpane.WebOptionPane;
import com.alee.laf.scroll.WebScrollPane;
import com.alee.laf.text.WebTextField;
import configs.ServerConfig;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.swing.*;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.File;
import java.util.Arrays;
import java.util.List;























 public class EventConfigGroup extends AbstractConfigGroup {
/*  26 */   private static final Logger log = LogManager.getLogger(EventConfigGroup.class);

/*  28 */   private final CheckBoxListModel listModel = new CheckBoxListModel();

   EventConfigGroup(ConfigPanel owner) {
/*  31 */     super(owner, "事件脚本");
   }


   public Component getPreview() {
/*  36 */     updateData();

/*  38 */     final WebCheckBoxList webCheckBoxList = new WebCheckBoxList(this.listModel);
/*  39 */     webCheckBoxList.setSelectionMode(0);

/*  41 */     this.listModel.addListDataListener(new ListDataListener()
         {
           public void intervalAdded(ListDataEvent e) {}




           public void intervalRemoved(ListDataEvent e) {}




           public void contentsChanged(ListDataEvent e) {
/*  54 */             String ret = "";
/*  55 */             for (CheckBoxCellData checkBoxCellData : EventConfigGroup.this.listModel.getElements()) {
/*  56 */               if (checkBoxCellData.isSelected()) {
/*  57 */                 ret = ret + checkBoxCellData.getUserObject() + ",";
               }
             }
/*  60 */             if (!ret.isEmpty()) {
/*  61 */               ret = ret.substring(0, ret.length() - 1);
             }
/*  63 */             EventConfigGroup.this.owner.getChangeSettingQueue().put("channel.server.events", ret);
/*  64 */             if (!EventConfigGroup.this.owner.getWebButtonApply().isEnabled()) {
/*  65 */               EventConfigGroup.this.owner.getWebButtonApply().setEnabled(true);
             }
           }
         });

/*  70 */     webCheckBoxList.setComponentPopupMenu((JPopupMenu)new WebPopupMenu()
         {

         });


































/* 108 */     final WebTextField search = new WebTextField(10);
/* 109 */     search.setInputPrompt("按脚本文件名搜索，不区分大小写，输入完成后按回车键直接转到结果");
/* 110 */     search.setInputPromptFont(search.getFont().deriveFont(2));
/* 111 */     search.setMaximumWidth(10);
/* 112 */     search.addKeyListener(new KeyAdapter()
         {
           public void keyPressed(KeyEvent e) {
/* 115 */             if (e.getKeyCode() == 10) {
/* 116 */               boolean find = false;
/* 117 */               for (CheckBoxCellData checkBoxCellData : EventConfigGroup.this.listModel.getElements()) {
/* 118 */                 if (search.getText().equalsIgnoreCase(String.valueOf(checkBoxCellData.getUserObject()))) {
/* 119 */                   webCheckBoxList.setSelectedIndex(EventConfigGroup.this.listModel.indexOf(checkBoxCellData));
/* 120 */                   find = true;
                   break;
                 }
               }
/* 124 */               if (!find) {
/* 125 */                 WebOptionPane.showMessageDialog((Component)EventConfigGroup.this.owner, "未找到脚本，请确认" + ServerConfig.WORLD_SCRIPTSPATH + "/event目录中存在该脚本", "查找脚本", 0);
               }
             }
           }
         });

/* 131 */     final TitleWebPanel titleWebPanel1 = new TitleWebPanel("事件脚本管理");
/* 132 */     titleWebPanel1.add((Component)(new GroupPanel(GroupingType.fillLast, 5, false, new Component[] { (Component)new GroupPanel(GroupingType.fillFirst, new Component[] { (Component)search, (Component)new WebButton("刷新脚本列表", 



/* 136 */                   loadIcon("switch.png")) {  } }), (Component)new WebScrollPane((Component)webCheckBoxList)





/* 142 */           })).setMargin(5));
/* 143 */     return (Component)titleWebPanel1;
   }




   private void updateData() {
/* 150 */     this.listModel.clear();
/* 151 */     List<String> events = Arrays.asList(ServerConfig.CHANNEL_EVENTS.split(","));
/* 152 */     File eventfiles = new File(ServerConfig.WORLD_SCRIPTSPATH + "/event");
/* 153 */     for (String s : eventfiles.list()) {
/* 154 */       String event = s.substring(0, s.indexOf("."));
/* 155 */       this.listModel.addCheckBoxElement(event, events.contains(event));
     }
   }
 }


/* Location:              C:\PGX\Server.jar!\server\console\groups\setting\EventConfigGroup.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */